<template>
	<view class="wrap">
		<block v-if="dataBuffer">
			<view class="top">
				<image :src="img" mode="widthFix" class="topBanner"></image>
				<image src="../../static/active.png" mode="widthFix" class="bottomBanner"></image>
			</view>
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</block>
		<!-- 无数据提示 -->
		<u-empty 
			text="暂无数据~~去逛逛~~" mode="list" 
			:show="!dataBuffer" 
			color="orange" icon-color="orange"
		></u-empty>
	</view>
</template>

<script>
	// 引入测试数据 可以测试使用
	// import list from '@/utils/active.data.js'
	export default {
		data() {
			return {
				activeData:{},
				loadStatus: 'loadmore',
				flowList: [],
				page:1,
				size:6,
				totalPage:0,
				dataBuffer:true,
				img:"",
				cateid:""
			}
		},
		onReachBottom(){
			this.page++
			if(this.page>this.totalPage){
				this.loadStatus="nomore"
				return
			}
			this.getgoodlist()
		},
		onLoad(option){
			// this.flowList = list;
			
			// 接参
			let {img,second_cateid,title}=JSON.parse(option.item)
			uni.setNavigationBarTitle({
				title
			})
			this.img=img
			this.cateid=second_cateid
			
			this.getgoodlist ()
		},
	
		methods: {
			
			// http://localhost:3000/api/getgoodlist  获取活动的数据列表
			async getgoodlist (){
				let [err,res]=await uni.request({
					url:this.$baseUrl+"/api/getgoodlist",
					data:{
						type:2,
						cateid:this.cateid,
						size:this.size,
						page:this.page
						
					}
				})
				if(err || res.data.code !=200){
					uni.showLoading({
						title:"加载中。。。"
					})
					
					return
				}
				// console.log(res);
				
				if(!res.data.list.goodData){
					// 空状态
					this.dataBuffer=false
					return
				}
				
				res.data.list.goodData.forEach(item=>{
					item.img=this.$baseUrl+item.img
				})
				this.totalPage=res.data.list.totalPage
				
				this.flowList=[...this.flowList,...res.data.list.goodData]
				
			},
			
			
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 引入样式
	@import '@/static/css/active.scss'
</style>
